﻿// -----------------------------------------------------------------------
// <copyright file="TinhThanh.cs" company="VDC" author="HuongNt">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.ENTITY
{
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using Microsoft.ApplicationBlocks.Data;
    using VDC.COMMON;
    
    /// <summary>
    /// Class TinhThanh.cs
    /// </summary>
    public class TinhThanh
    {
        /// <summary>
        /// Gets or sets the IdTinhThanh.
        /// </summary>
        /// <value>
        /// The IdTinhThanh.
        /// </value>
        public int IdTinhThanh { get; set; }

        /// <summary>
        /// Gets or sets the MaTinhThanh.
        /// </summary>
        /// <value>
        /// The MaTinhThanh.
        /// </value>
        public string MaTinhThanh { get; set; }

        /// <summary>
        /// Gets or sets the TenTinhThanh.
        /// </summary>
        /// <value>
        /// The TenTinhThanh.
        /// </value>
        public string TenTinhThanh { get; set; }

        /// <summary>
        /// Gets Quan huyen
        /// </summary>
        public IList<QuanHuyen> Quanhuyen
        {
            get
            {
                IList<QuanHuyen> lstQuanhuyen = new List<QuanHuyen>();
                QuanHuyen quanhuyen;
                string[] param = new string[1];
                param[0] = this.IdTinhThanh.ToString();
                ////Thực thi store lấy quận huyện theo Id tỉnh thành
                SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneQuanHuyenByIdTinhThanh, param);
                while (reader.Read())
                {
                    quanhuyen = new QuanHuyen();
                    if (!reader.IsDBNull(0))
                    {
                        quanhuyen.IdQuanHuyen = reader.GetInt32(0);
                    }

                    if (!reader.IsDBNull(1))
                    {
                        quanhuyen.IdTinhThanh = reader.GetInt32(1);
                    }

                    if (!reader.IsDBNull(2))
                    {
                        quanhuyen.MaQuanHuyen = reader.GetString(2);
                    }

                    if (!reader.IsDBNull(3))
                    {
                        quanhuyen.TenQuanHuyen = reader.GetString(3);
                    }

                    lstQuanhuyen.Add(quanhuyen);
                }

                reader.Close();
                reader.Dispose();
                return lstQuanhuyen;
            }
        }
    }
}
